package core.process;

import core.utils.EPara;
import core.process.pack.PostPack;
import core.rb.PB;
import core.rb.r.PR;
import java.util.ArrayList;
import java.util.concurrent.CountDownLatch;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class Post{
    protected PB pb;
    double [][] posts;
    public Post(PB pb, double [][] np){
        this.pb = pb;
        this.posts = np;
    }
    public boolean setPosts() throws Exception{
        int size = (int)((pb.getSize() / EPara.THREADS));
        int i = 0;
        ArrayList <PB> packs = new ArrayList();
        ArrayList <PR> pack;
        for(int x = 0; x<EPara.THREADS; x++){
            pack = new ArrayList();
            for(int y = 0; y<size; y++){pack.add(pb.getRead(i++));}
            packs.add(new PB(pb.getRef(), pack));
        }
        PB fPack = packs.get(0);
        for(int x=i; x<pb.getSize(); x++){fPack.add(pb.getRead(i++)); }
        CountDownLatch cdl = new CountDownLatch(packs.size());
        for (int x = 0; x < packs.size(); x++){ new PostPack(cdl, packs.get(x), this.posts);}
        cdl.await();
        return true;
    }
}